using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using ImageGear.Core;
using ImageGear.TWAIN;

namespace TWAIN
{
	/// <summary>
	/// Summary description for frmScanParams.
	/// </summary>
	public class frmScanParams : System.Windows.Forms.Form
	{
		#region Controls
		private System.Windows.Forms.Button btnOK;
		private System.Windows.Forms.Button btnCancel;
		private System.Windows.Forms.GroupBox grpCapture;
		private System.Windows.Forms.GroupBox grpRes;
		private System.Windows.Forms.GroupBox grpBrtCont;
		private System.Windows.Forms.TextBox txtPgs;
		private System.Windows.Forms.Label lblPages;
		private System.Windows.Forms.GroupBox grpBtDep;
		private System.Windows.Forms.GroupBox grpPixTp;
		private System.Windows.Forms.GroupBox grpPixFlav;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.TextBox txtLeft;
		private System.Windows.Forms.TextBox txtTop;
		private System.Windows.Forms.TextBox txtRight;
		private System.Windows.Forms.TextBox txtBot;
		private System.Windows.Forms.TextBox txtBrt;
		private System.Windows.Forms.TextBox txtCont;
		private System.Windows.Forms.RadioButton rbOneBt;
		private System.Windows.Forms.RadioButton rbFourBt;
		private System.Windows.Forms.RadioButton rbEightBit;
		private System.Windows.Forms.RadioButton rbBW;
		private System.Windows.Forms.RadioButton rbGray;
		private System.Windows.Forms.RadioButton rbRGB;
		private System.Windows.Forms.RadioButton rbPal;
		private System.Windows.Forms.RadioButton rbChoc;
		private System.Windows.Forms.RadioButton rbVan;

		private MainForm m_Par;
		private System.Windows.Forms.TextBox txtXRes;
		private System.Windows.Forms.TextBox txtYRes;
#endregion Controls
		/// <summary>
		/// Required designer variable.
		/// </summary>
		/// 
		private System.ComponentModel.Container components = null;
		private bool[] m_aGrpChng = new bool[6] {false, false, false, false, false, false}; 
		private bool m_bIsInit = false;
		private enum enumFldChanged
		{
			CAPTRECT = 0,
			RESOL  = 1,
			BRTCONT = 2,
			BTDEP = 3,
			PIXTP = 4,
			PIXFLAV = 5
		}

		public frmScanParams(MainForm par)
		{
			InitializeComponent();
			m_Par = par;
		}

		private void frmScanParams_Load(object sender, System.EventArgs e)
		{
			InitUI();
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Helpers
		private void InitUI()
		{
			GetLayout();
			GetXYResolution();
			GetBrightness();
			GetContrast();
			GetClrDepth();
			GetPixType();
			GetPixFlav();
			m_bIsInit = true;
		}

		private void GetLayout()
		{
			try
			{
				ImGearDoubleRectangle dr = m_Par.IMGearTWAIN.GetImageLayout();
				txtLeft.Text = dr.Left.ToString();
				txtTop.Text = dr.Top.ToString();
				txtRight.Text = dr.Right.ToString();
				txtBot.Text = dr.Bottom.ToString();
			}
			catch
			{
				foreach(Control ctl in grpCapture.Controls)
					if(ctl is TextBox)
						ctl.Enabled = false;
			}
		}

		private void GetXYResolution()
		{
			try
			{
				ImGearCap cap = null; 
				cap = m_Par.IMGearTWAIN.GetCapability(ImGearCapabilities.ICAP_XRESOLUTION, 
					ImGearMessages.GETCURRENT);
				if(cap != null)
					txtXRes.Text = ((ImGearCapOneValue)cap).Value.ToString();
			}
			catch
			{
				txtXRes.Enabled = false;
			}

			try
			{
				ImGearCap cap = null;
				cap = m_Par.IMGearTWAIN.GetCapability(ImGearCapabilities.ICAP_YRESOLUTION, 
					ImGearMessages.GETCURRENT);
				if(cap != null)
					txtYRes.Text = ((ImGearCapOneValue)cap).Value.ToString();
			}
			catch
			{
				txtYRes.Enabled = false;
			}
		}

		private void GetBrightness()
		{
			try
			{
				ImGearCap cap = null;
				cap = m_Par.IMGearTWAIN.GetCapability(ImGearCapabilities.ICAP_BRIGHTNESS, 
					ImGearMessages.GETCURRENT);
				if(cap != null)
					txtBrt.Text = ((ImGearCapOneValue)cap).Value.ToString();
			}
			catch
			{
				txtBrt.Enabled = false;
			}
		}

		private void GetContrast()
		{
			try
			{
				ImGearCap cap = null;
				cap = m_Par.IMGearTWAIN.GetCapability(ImGearCapabilities.ICAP_CONTRAST, 
					ImGearMessages.GETCURRENT);
				if(cap != null)
					txtCont.Text = ((ImGearCapOneValue)cap).Value.ToString();
			}
			catch
			{
				txtCont.Enabled = false;
			}
		}

		private void GetClrDepth()
		{
			ImGearCap cap = null;
			cap = m_Par.IMGearTWAIN.GetCapability(ImGearCapabilities.ICAP_BITDEPTH, 
				ImGearMessages.GETCURRENT);
			if(cap != null)
			{
				string depth = ((ImGearCapOneValue)cap).Value.ToString();
				foreach(Control ctl in grpBtDep.Controls)
					if((ctl is RadioButton))
					{
						ctl.Enabled = true;
						if(ctl.Tag.ToString() == depth)
							((RadioButton)ctl).Checked = true;
					}			
			}
		}

		private void GetPixType()
		{
			string sCap = "";
			ImGearCap cap = null;
			cap = m_Par.IMGearTWAIN.GetCapability(ImGearCapabilities.ICAP_PIXELTYPE, 
				ImGearMessages.GETCURRENT);
			if(cap != null)
			{
				switch (cap.ContainerType)
				{
					case ImGearContainerType.ONEVALUE:
						sCap = ((ImGearCapOneValue)cap).Value.ToString();
						break;
					case ImGearContainerType.ENUMERATION:
						ImGearCapEnumeration ecap = (ImGearCapEnumeration) cap;
						sCap = ecap[ecap.CurrentValueIndex].ToString();
						break;
				}
				switch (sCap)
				{
					case "0": 
						rbBW.Checked = true;
						rbBWChanged();
						break;
					case "1":
						rbGray.Checked = true;
						rbGrayChanged();
						break;
					case "2":
						rbRGB.Checked = true;
						rbRGBChanged();
						break;
					case "3":
						rbPal.Checked = true;
						rbPalChanged();
						break;
					default:
						break;
				}
			}
			else
				foreach(Control ctl in grpPixTp.Controls)
					if(ctl is RadioButton)
						ctl.Enabled = false;
		}

		private void GetPixFlav()
		{
			ImGearCap cap = null;
			cap = m_Par.IMGearTWAIN.GetCapability(ImGearCapabilities.ICAP_PIXELFLAVOR, 
				ImGearMessages.GETCURRENT);
			if(cap != null)
			{
				if(((ImGearCapOneValue)cap).Value.ToString() == "0")
					rbChoc.Checked = true;
				else
					rbVan.Checked = true;
			}
		}

		private void SetCaps()
		{
			if(m_aGrpChng[((int)enumFldChanged.CAPTRECT)])
				SetLayout();
			if(m_aGrpChng[((int)enumFldChanged.RESOL)])
				SetXYResolution();
			if(m_aGrpChng[((int)enumFldChanged.BRTCONT)])
			{
				SetBrightness();
				SetContrast();
			}
			if(m_aGrpChng[((int)enumFldChanged.PIXTP)] || m_aGrpChng[((int)enumFldChanged.BTDEP)])
			{
				SetPixType();
				SetClrDepth();
			}
			if(m_aGrpChng[((int)enumFldChanged.PIXFLAV)])
				SetPixFlav();
		}

		private void SetLayout()
		{
			foreach(Control ctl in grpCapture.Controls)
				if(ctl is TextBox)
					if(!ctl.Enabled || (((TextBox)ctl).Text == ""))
						return;
			ImGearDoubleRectangle dr = new ImGearDoubleRectangle();
			try
			{
				dr.Left = double.Parse(txtLeft.Text);
				dr.Top = double.Parse(txtTop.Text);
				dr.Right = double.Parse(txtRight.Text);
				dr.Bottom = double.Parse(txtBot.Text);
			}
			catch
			{
				return;
			}
			m_Par.IMGearTWAIN.SetImageLayout(dr);
		}

		private void SetXYResolution()
		{
			foreach(Control ctl in grpRes.Controls)
				if(ctl is TextBox)
					if(!ctl.Enabled || (((TextBox)ctl).Text == ""))
						return;
			Double dXres;
			Double dYres;
			try
			{
				dXres = Double.Parse(txtXRes.Text);
				dYres = Double.Parse(txtYRes.Text);
			}
			catch
			{
				return;
			}
			ImGearCapOneValue cap = new ImGearCapOneValue(ImGearCapabilities.ICAP_XRESOLUTION);
			cap.Value = dXres;
			m_Par.IMGearTWAIN.SetCapability(cap, ImGearMessages.SET);
			ImGearCapOneValue cap2 = new ImGearCapOneValue(ImGearCapabilities.ICAP_YRESOLUTION);
			cap.Value = dYres;
			m_Par.IMGearTWAIN.SetCapability(cap, ImGearMessages.SET);
		}

		private void SetBrightness()
		{
			if(!(txtBrt.Enabled) || txtBrt.Text == "")
				return;
			Double dbrt;
			try
			{
				dbrt = Double.Parse(txtBrt.Text);
			}
			catch
			{
				return;
			}
			ImGearCapOneValue cap = new ImGearCapOneValue(ImGearCapabilities.ICAP_BRIGHTNESS);
			cap.Value = dbrt;
			m_Par.IMGearTWAIN.SetCapability(cap, ImGearMessages.SET);
		}

		private void SetContrast()
		{
			if(!(txtCont.Enabled) || txtCont.Text == "")
				return;
			Double dCont;
			try
			{
				dCont = Double.Parse(txtCont.Text);
			}
			catch
			{
				return;
			}
			ImGearCapOneValue cap = new ImGearCapOneValue(ImGearCapabilities.ICAP_CONTRAST);
			cap.Value = dCont;
			m_Par.IMGearTWAIN.SetCapability(cap, ImGearMessages.SET);
		}

		private void SetPixType()
		{
			if(!rbBW.Enabled)
				return;
			string sSelTxt = null;
			foreach(Control ctl in grpPixTp.Controls)
				if(ctl is RadioButton && ((RadioButton)ctl).Checked)
				{
					sSelTxt = ((RadioButton)ctl).Text;
					break;
				}
			if(sSelTxt == null)
				return;
			ImGearCapOneValue cap = new ImGearCapOneValue(ImGearCapabilities.ICAP_PIXELTYPE);
			switch(sSelTxt)
			{
				case "B/W":
					cap.Value = ImGearPixelType.BW;
					break;
				case "Gray":
					cap.Value = ImGearPixelType.GRAY;
					break;
				case "RGB":
					cap.Value = ImGearPixelType.RGB;
					break;
				case "Palette":
					cap.Value = ImGearPixelType.PALETTE;
					break;
				default:
					return;
			}
			m_Par.IMGearTWAIN.SetCapability(cap, ImGearMessages.SET);
		}

		private void SetClrDepth()
		{
			string selRB = "";
			foreach(Control ctl in grpBtDep.Controls)
				if((ctl is RadioButton) &&((RadioButton)ctl).Enabled &&((RadioButton)ctl).Checked)
				{
					selRB = ((RadioButton)ctl).Tag.ToString();
					break;
				}
			if(selRB != "")
			{
				ImGearCapOneValue cap = new ImGearCapOneValue(ImGearCapabilities.ICAP_BITDEPTH);
				switch(selRB)
				{
					case "1":
						cap.Value = 1;
						break;
					case "4":
						cap.Value = 4;
						break;
					case "8": 
						cap.Value = 8;
						break;
					default:
						return;
				}
				m_Par.IMGearTWAIN.SetCapability(cap, ImGearMessages.SET);
			}
		}

		private void SetPixFlav()
		{
			if(!rbChoc.Enabled || !rbVan.Enabled)
				return;

			ImGearCapOneValue cap = new ImGearCapOneValue(ImGearCapabilities.ICAP_PIXELFLAVOR);

			if(rbChoc.Checked)
				cap.Value = ImGearPixelFlavor.CHOCOLATE;
			else
				cap.Value = ImGearPixelFlavor.VANILLA;
			m_Par.IMGearTWAIN.SetCapability(cap, ImGearMessages.SET);
		}

		private void PixTpChanged(string sRbNm)
		{
			m_bIsInit = false;
			switch(sRbNm)
			{
				case "rbBW":
					rbBWChanged();
					break;
				case "rbGray":
					rbGrayChanged();
					break;
				case "rbRGB":
					rbRGBChanged();
					break;
				case "rbPal":
					rbPalChanged();
					break;
				default:
					break;
			}
			m_bIsInit = true;
		}

		private void rbBWChanged()
		{
			rbOneBt.Checked = true;
			rbOneBt.Enabled = true;
			rbFourBt.Enabled = false;
			rbEightBit.Enabled = false;
		}

		private void rbGrayChanged()
		{
			rbEightBit.Checked = true;
			rbEightBit.Enabled = true;
			rbFourBt.Enabled = true;
			rbOneBt.Enabled = false;
		}

		private void rbRGBChanged()
		{
			rbEightBit.Checked = true;
			rbEightBit.Enabled = true;
			rbOneBt.Enabled = false;
			rbFourBt.Enabled = false;
		}

		private void rbPalChanged()
		{
			rbEightBit.Checked = true;
			rbEightBit.Enabled = true;
			rbFourBt.Enabled = false;
			rbOneBt.Enabled = false;
		}

		#endregion  Helpers

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.btnOK = new System.Windows.Forms.Button();
			this.btnCancel = new System.Windows.Forms.Button();
			this.grpCapture = new System.Windows.Forms.GroupBox();
			this.txtBot = new System.Windows.Forms.TextBox();
			this.txtRight = new System.Windows.Forms.TextBox();
			this.txtTop = new System.Windows.Forms.TextBox();
			this.txtLeft = new System.Windows.Forms.TextBox();
			this.label4 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.grpRes = new System.Windows.Forms.GroupBox();
			this.txtYRes = new System.Windows.Forms.TextBox();
			this.txtXRes = new System.Windows.Forms.TextBox();
			this.label6 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.grpBrtCont = new System.Windows.Forms.GroupBox();
			this.txtCont = new System.Windows.Forms.TextBox();
			this.txtBrt = new System.Windows.Forms.TextBox();
			this.label8 = new System.Windows.Forms.Label();
			this.label7 = new System.Windows.Forms.Label();
			this.txtPgs = new System.Windows.Forms.TextBox();
			this.lblPages = new System.Windows.Forms.Label();
			this.grpBtDep = new System.Windows.Forms.GroupBox();
			this.rbEightBit = new System.Windows.Forms.RadioButton();
			this.rbFourBt = new System.Windows.Forms.RadioButton();
			this.rbOneBt = new System.Windows.Forms.RadioButton();
			this.label9 = new System.Windows.Forms.Label();
			this.grpPixTp = new System.Windows.Forms.GroupBox();
			this.rbPal = new System.Windows.Forms.RadioButton();
			this.rbRGB = new System.Windows.Forms.RadioButton();
			this.rbGray = new System.Windows.Forms.RadioButton();
			this.rbBW = new System.Windows.Forms.RadioButton();
			this.grpPixFlav = new System.Windows.Forms.GroupBox();
			this.rbVan = new System.Windows.Forms.RadioButton();
			this.rbChoc = new System.Windows.Forms.RadioButton();
			this.grpCapture.SuspendLayout();
			this.grpRes.SuspendLayout();
			this.grpBrtCont.SuspendLayout();
			this.grpBtDep.SuspendLayout();
			this.grpPixTp.SuspendLayout();
			this.grpPixFlav.SuspendLayout();
			this.SuspendLayout();
			// 
			// btnOK
			// 
			this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
			this.btnOK.Location = new System.Drawing.Point(416, 24);
			this.btnOK.Name = "btnOK";
			this.btnOK.TabIndex = 0;
			this.btnOK.Text = "&OK";
			this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
			// 
			// btnCancel
			// 
			this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.btnCancel.Location = new System.Drawing.Point(416, 56);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.TabIndex = 1;
			this.btnCancel.Text = "Cancel";
			// 
			// grpCapture
			// 
			this.grpCapture.Controls.Add(this.txtBot);
			this.grpCapture.Controls.Add(this.txtRight);
			this.grpCapture.Controls.Add(this.txtTop);
			this.grpCapture.Controls.Add(this.txtLeft);
			this.grpCapture.Controls.Add(this.label4);
			this.grpCapture.Controls.Add(this.label3);
			this.grpCapture.Controls.Add(this.label2);
			this.grpCapture.Controls.Add(this.label1);
			this.grpCapture.Location = new System.Drawing.Point(8, 16);
			this.grpCapture.Name = "grpCapture";
			this.grpCapture.Size = new System.Drawing.Size(264, 160);
			this.grpCapture.TabIndex = 2;
			this.grpCapture.TabStop = false;
			this.grpCapture.Text = "Capture Rectangle";
			// 
			// txtBot
			// 
			this.txtBot.Location = new System.Drawing.Point(120, 120);
			this.txtBot.Name = "txtBot";
			this.txtBot.Size = new System.Drawing.Size(136, 20);
			this.txtBot.TabIndex = 7;
			this.txtBot.Text = "";
			this.txtBot.TextChanged += new System.EventHandler(this.txt_TextChanged);
			// 
			// txtRight
			// 
			this.txtRight.Location = new System.Drawing.Point(120, 88);
			this.txtRight.Name = "txtRight";
			this.txtRight.Size = new System.Drawing.Size(136, 20);
			this.txtRight.TabIndex = 6;
			this.txtRight.Text = "";
			this.txtRight.TextChanged += new System.EventHandler(this.txt_TextChanged);
			// 
			// txtTop
			// 
			this.txtTop.Location = new System.Drawing.Point(120, 56);
			this.txtTop.Name = "txtTop";
			this.txtTop.Size = new System.Drawing.Size(136, 20);
			this.txtTop.TabIndex = 5;
			this.txtTop.Text = "";
			this.txtTop.TextChanged += new System.EventHandler(this.txt_TextChanged);
			// 
			// txtLeft
			// 
			this.txtLeft.Location = new System.Drawing.Point(120, 24);
			this.txtLeft.Name = "txtLeft";
			this.txtLeft.Size = new System.Drawing.Size(136, 20);
			this.txtLeft.TabIndex = 4;
			this.txtLeft.Text = "";
			this.txtLeft.TextChanged += new System.EventHandler(this.txt_TextChanged);
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(8, 120);
			this.label4.Name = "label4";
			this.label4.TabIndex = 3;
			this.label4.Text = "Bottom:";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(8, 88);
			this.label3.Name = "label3";
			this.label3.TabIndex = 2;
			this.label3.Text = "Right:";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(8, 56);
			this.label2.Name = "label2";
			this.label2.TabIndex = 1;
			this.label2.Text = "Top:";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 24);
			this.label1.Name = "label1";
			this.label1.TabIndex = 0;
			this.label1.Text = "Left:";
			// 
			// grpRes
			// 
			this.grpRes.Controls.Add(this.txtYRes);
			this.grpRes.Controls.Add(this.txtXRes);
			this.grpRes.Controls.Add(this.label6);
			this.grpRes.Controls.Add(this.label5);
			this.grpRes.Location = new System.Drawing.Point(8, 184);
			this.grpRes.Name = "grpRes";
			this.grpRes.Size = new System.Drawing.Size(264, 88);
			this.grpRes.TabIndex = 3;
			this.grpRes.TabStop = false;
			this.grpRes.Text = "Resolution";
			// 
			// txtYRes
			// 
			this.txtYRes.Location = new System.Drawing.Point(120, 56);
			this.txtYRes.Name = "txtYRes";
			this.txtYRes.Size = new System.Drawing.Size(136, 20);
			this.txtYRes.TabIndex = 3;
			this.txtYRes.Text = "";
			this.txtYRes.TextChanged += new System.EventHandler(this.txt_TextChanged);
			// 
			// txtXRes
			// 
			this.txtXRes.Location = new System.Drawing.Point(120, 24);
			this.txtXRes.Name = "txtXRes";
			this.txtXRes.Size = new System.Drawing.Size(136, 20);
			this.txtXRes.TabIndex = 2;
			this.txtXRes.Text = "";
			this.txtXRes.TextChanged += new System.EventHandler(this.txt_TextChanged);
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(8, 56);
			this.label6.Name = "label6";
			this.label6.TabIndex = 1;
			this.label6.Text = "Y-Res:";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(8, 24);
			this.label5.Name = "label5";
			this.label5.TabIndex = 0;
			this.label5.Text = "X-Res:";
			// 
			// grpBrtCont
			// 
			this.grpBrtCont.Controls.Add(this.txtCont);
			this.grpBrtCont.Controls.Add(this.txtBrt);
			this.grpBrtCont.Controls.Add(this.label8);
			this.grpBrtCont.Controls.Add(this.label7);
			this.grpBrtCont.Location = new System.Drawing.Point(8, 280);
			this.grpBrtCont.Name = "grpBrtCont";
			this.grpBrtCont.Size = new System.Drawing.Size(264, 88);
			this.grpBrtCont.TabIndex = 4;
			this.grpBrtCont.TabStop = false;
			this.grpBrtCont.Text = "Brightness/Contrast";
			// 
			// txtCont
			// 
			this.txtCont.Location = new System.Drawing.Point(120, 56);
			this.txtCont.Name = "txtCont";
			this.txtCont.Size = new System.Drawing.Size(136, 20);
			this.txtCont.TabIndex = 3;
			this.txtCont.Text = "";
			this.txtCont.TextChanged += new System.EventHandler(this.txt_TextChanged);
			// 
			// txtBrt
			// 
			this.txtBrt.Location = new System.Drawing.Point(120, 24);
			this.txtBrt.Name = "txtBrt";
			this.txtBrt.Size = new System.Drawing.Size(136, 20);
			this.txtBrt.TabIndex = 2;
			this.txtBrt.Text = "";
			this.txtBrt.TextChanged += new System.EventHandler(this.txt_TextChanged);
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(8, 56);
			this.label8.Name = "label8";
			this.label8.TabIndex = 1;
			this.label8.Text = "Contrast:";
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(8, 24);
			this.label7.Name = "label7";
			this.label7.TabIndex = 0;
			this.label7.Text = "Brightness:";
			// 
			// txtPgs
			// 
			this.txtPgs.Location = new System.Drawing.Point(168, 392);
			this.txtPgs.Name = "txtPgs";
			this.txtPgs.Size = new System.Drawing.Size(72, 20);
			this.txtPgs.TabIndex = 5;
			this.txtPgs.Text = "-1";
			// 
			// lblPages
			// 
			this.lblPages.Location = new System.Drawing.Point(8, 392);
			this.lblPages.Name = "lblPages";
			this.lblPages.Size = new System.Drawing.Size(136, 23);
			this.lblPages.TabIndex = 6;
			this.lblPages.Text = "Number of Pages to Scan";
			// 
			// grpBtDep
			// 
			this.grpBtDep.Controls.Add(this.rbEightBit);
			this.grpBtDep.Controls.Add(this.rbFourBt);
			this.grpBtDep.Controls.Add(this.rbOneBt);
			this.grpBtDep.Controls.Add(this.label9);
			this.grpBtDep.Location = new System.Drawing.Point(280, 16);
			this.grpBtDep.Name = "grpBtDep";
			this.grpBtDep.Size = new System.Drawing.Size(128, 160);
			this.grpBtDep.TabIndex = 7;
			this.grpBtDep.TabStop = false;
			this.grpBtDep.Text = "Bit Depth";
			// 
			// rbEightBit
			// 
			this.rbEightBit.Enabled = false;
			this.rbEightBit.Location = new System.Drawing.Point(8, 80);
			this.rbEightBit.Name = "rbEightBit";
			this.rbEightBit.Size = new System.Drawing.Size(72, 24);
			this.rbEightBit.TabIndex = 3;
			this.rbEightBit.Tag = "8";
			this.rbEightBit.Text = "8-Bit";
			this.rbEightBit.CheckedChanged += new System.EventHandler(this.rb_CheckedChanged);
			// 
			// rbFourBt
			// 
			this.rbFourBt.Enabled = false;
			this.rbFourBt.Location = new System.Drawing.Point(8, 48);
			this.rbFourBt.Name = "rbFourBt";
			this.rbFourBt.Size = new System.Drawing.Size(64, 24);
			this.rbFourBt.TabIndex = 2;
			this.rbFourBt.Tag = "4";
			this.rbFourBt.Text = "4-Bit";
			this.rbFourBt.CheckedChanged += new System.EventHandler(this.rb_CheckedChanged);
			// 
			// rbOneBt
			// 
			this.rbOneBt.Enabled = false;
			this.rbOneBt.Location = new System.Drawing.Point(8, 16);
			this.rbOneBt.Name = "rbOneBt";
			this.rbOneBt.Size = new System.Drawing.Size(64, 24);
			this.rbOneBt.TabIndex = 1;
			this.rbOneBt.Tag = "1";
			this.rbOneBt.Text = "1-Bit";
			this.rbOneBt.CheckedChanged += new System.EventHandler(this.rb_CheckedChanged);
			// 
			// label9
			// 
			this.label9.Location = new System.Drawing.Point(8, 112);
			this.label9.Name = "label9";
			this.label9.Size = new System.Drawing.Size(112, 40);
			this.label9.TabIndex = 0;
			this.label9.Text = "Note: For RGB, this is bits per channel";
			// 
			// grpPixTp
			// 
			this.grpPixTp.Controls.Add(this.rbPal);
			this.grpPixTp.Controls.Add(this.rbRGB);
			this.grpPixTp.Controls.Add(this.rbGray);
			this.grpPixTp.Controls.Add(this.rbBW);
			this.grpPixTp.Location = new System.Drawing.Point(280, 184);
			this.grpPixTp.Name = "grpPixTp";
			this.grpPixTp.Size = new System.Drawing.Size(128, 144);
			this.grpPixTp.TabIndex = 8;
			this.grpPixTp.TabStop = false;
			this.grpPixTp.Text = "Pixel Type";
			// 
			// rbPal
			// 
			this.rbPal.Location = new System.Drawing.Point(8, 112);
			this.rbPal.Name = "rbPal";
			this.rbPal.Size = new System.Drawing.Size(64, 24);
			this.rbPal.TabIndex = 3;
			this.rbPal.Text = "Palette";
			this.rbPal.CheckedChanged += new System.EventHandler(this.rb_CheckedChanged);
			// 
			// rbRGB
			// 
			this.rbRGB.Location = new System.Drawing.Point(8, 80);
			this.rbRGB.Name = "rbRGB";
			this.rbRGB.Size = new System.Drawing.Size(56, 24);
			this.rbRGB.TabIndex = 2;
			this.rbRGB.Text = "RGB";
			this.rbRGB.CheckedChanged += new System.EventHandler(this.rb_CheckedChanged);
			// 
			// rbGray
			// 
			this.rbGray.Location = new System.Drawing.Point(8, 48);
			this.rbGray.Name = "rbGray";
			this.rbGray.Size = new System.Drawing.Size(56, 24);
			this.rbGray.TabIndex = 1;
			this.rbGray.Text = "Gray";
			this.rbGray.CheckedChanged += new System.EventHandler(this.rb_CheckedChanged);
			// 
			// rbBW
			// 
			this.rbBW.Location = new System.Drawing.Point(8, 16);
			this.rbBW.Name = "rbBW";
			this.rbBW.Size = new System.Drawing.Size(56, 24);
			this.rbBW.TabIndex = 0;
			this.rbBW.Text = "B/W";
			this.rbBW.CheckedChanged += new System.EventHandler(this.rb_CheckedChanged);
			// 
			// grpPixFlav
			// 
			this.grpPixFlav.Controls.Add(this.rbVan);
			this.grpPixFlav.Controls.Add(this.rbChoc);
			this.grpPixFlav.Location = new System.Drawing.Point(280, 336);
			this.grpPixFlav.Name = "grpPixFlav";
			this.grpPixFlav.Size = new System.Drawing.Size(128, 80);
			this.grpPixFlav.TabIndex = 9;
			this.grpPixFlav.TabStop = false;
			this.grpPixFlav.Text = "Pixel Flavour";
			// 
			// rbVan
			// 
			this.rbVan.Location = new System.Drawing.Point(8, 48);
			this.rbVan.Name = "rbVan";
			this.rbVan.Size = new System.Drawing.Size(72, 24);
			this.rbVan.TabIndex = 1;
			this.rbVan.Text = "Vanilla";
			this.rbVan.CheckedChanged += new System.EventHandler(this.rb_CheckedChanged);
			// 
			// rbChoc
			// 
			this.rbChoc.Location = new System.Drawing.Point(8, 16);
			this.rbChoc.Name = "rbChoc";
			this.rbChoc.Size = new System.Drawing.Size(80, 24);
			this.rbChoc.TabIndex = 0;
			this.rbChoc.Text = "Chocolate";
			this.rbChoc.CheckedChanged += new System.EventHandler(this.rb_CheckedChanged);
			// 
			// frmScanParams
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.CancelButton = this.btnCancel;
			this.ClientSize = new System.Drawing.Size(498, 424);
			this.Controls.Add(this.grpPixFlav);
			this.Controls.Add(this.grpPixTp);
			this.Controls.Add(this.grpBtDep);
			this.Controls.Add(this.lblPages);
			this.Controls.Add(this.txtPgs);
			this.Controls.Add(this.grpBrtCont);
			this.Controls.Add(this.grpRes);
			this.Controls.Add(this.grpCapture);
			this.Controls.Add(this.btnCancel);
			this.Controls.Add(this.btnOK);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "frmScanParams";
			this.Text = "Scan Parameters";
			this.Load += new System.EventHandler(this.frmScanParams_Load);
			this.grpCapture.ResumeLayout(false);
			this.grpRes.ResumeLayout(false);
			this.grpBrtCont.ResumeLayout(false);
			this.grpBtDep.ResumeLayout(false);
			this.grpPixTp.ResumeLayout(false);
			this.grpPixFlav.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		#region Handlers

		private void btnOK_Click(object sender, System.EventArgs e)
		{
			SetCaps();
			this.Close();
		}
		
		private void txt_TextChanged(object sender, System.EventArgs e)
		{
			if(!m_bIsInit)
				return;
			string txt = ((Control)sender).Parent.Name;
			switch(txt)
			{
				case "grpCapture":
					m_aGrpChng[((int)enumFldChanged.CAPTRECT)] = true;
					break;
				case "grpRes":
					m_aGrpChng[((int)enumFldChanged.RESOL)] = true;
					break;
				case "grpBrtCont":
					m_aGrpChng[((int)enumFldChanged.BRTCONT)] = true;
					break;
				default:
					break;
			}
		}

		private void rb_CheckedChanged(object sender, System.EventArgs e)
		{
			if(!m_bIsInit)
				return;
			string txt = ((Control)sender).Parent.Name;
			switch(txt)
			{
				case "grpBtDep":
					m_aGrpChng[((int)enumFldChanged.BTDEP)] = true;
					break;
				case "grpPixFlav":
					m_aGrpChng[((int)enumFldChanged.PIXFLAV)] = true;
					break;
				case "grpPixTp":
					m_aGrpChng[((int)enumFldChanged.PIXTP)] = true;
					PixTpChanged(((RadioButton)sender).Name);
					break;
				default:
					break;
			}
		}
		#endregion Handlers
	}
}
